<template>
	<div v-if="notFound">
		<div class="card-details-index">
			<card-details></card-details>
		</div>
	</div>
</template>

<script>

	import cardDetails from './card-details';
	import common from '../../utils/common.js';

	export default {
		data:function(){
			return {
				notFound:true
			}
		},
		route:{
			data () {
				common.setTitle('卡详情');
				//判断是否进入404页面
				if(!this.$route.params.cardCode){

					this.notFound = false;
					common.goNotFound();
					return false;

				}
				var cardData,cardServerData;

				this.$http.post(common.isdev()+'/cxjCard/detail.htm',{
					cardId:this.$route.params.cardCode
				}).then(function ( d ){
						
						cardServerData = typeof d.data === 'object' ? d.data : JSON.parse(d.data);
						
						sessionStorage.cardServerCodeList = '';
						if(cardServerData.result === 0){
							//进入404页面
							this.notFound = false;
							common.goNotFound();
							//common.Toast("请求错误");
						}
						else if(cardServerData.result === 1){

							var cardServerCodeList;

							var thisCardCode = this.$route.params.cardCode,

							cardData = JSON.parse(localStorage.cardData);
							
							if(thisCardCode != localStorage.thisCardNo){
								sessionStorage.cacheSeverLocalStorage = '';
							}
							localStorage.thisCardNo = thisCardCode;
							
							for(var i = 0; i < cardData.length; i++){

								if(thisCardCode == cardData[i].cardNo){

									this.$broadcast("cardDetailsData",cardData[i],thisCardCode,cardServerData.obj);

								}
							}
							//装填S码
							for(var j = 0; j < cardServerData.obj.cardItemVo.length; j++){

								if(cardServerCodeList === undefined){

									cardServerCodeList = cardServerData.obj.cardItemVo[j].serviceNo;

								}else{

									cardServerCodeList += ","+cardServerData.obj.cardItemVo[j].serviceNo;

								}

							}
							sessionStorage.setItem("cardServerCodeList",cardServerCodeList);

						}
						else if(cardServerData.result === -99){

							common.goLogin();

						}
					}, function ( error ) {

						common.Toast(error.data);
						
					});
			}
		},
		components: {
			cardDetails
		},
		ready:function(){
			common.ANA_Analytics();
		}
	}
	
</script>